<?php include 'inc/teacher_head.php';?>
<div class="layui-container">

    <div style='text-align:center;padding-top:20px;'>
        <a class="layui-btn layui-btn-lg b1" id="uploadGames"> 点此上传游戏，支持多选（游戏分值可修改）</a>
    </div>

    <div style='width: 700px;margin:10px auto;'>
        <table id="games" lay-filter="games"></table>
    </div>





</div>
            <script id="del" type="text/html">
                <a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-radius" lay-event="del">
                    &nbsp; <i class="layui-icon layui-icon-delete"></i>删 除 &nbsp;</a>
            </script>



<script language="javascript">
    layui.use(function () {
            var $ = layui.$,
                upload = layui.upload,
                table = layui.table;
            $("#nav_game").addClass('layui-this'); //设置导航当前选中项的样式

            //监听删除
            table.on('tool(games)', function (obj) {
                if (obj.event === 'del') {
                    // layer.confirm('真的删除该游戏吗？', {icon: 3}, function (index) {
                        $.post('/teacher/delGame', {data: obj.data}, function (msg) {
                            obj.del();
                            layer.msg('删除成功');
                        });
                        layer.close(index);
                    // });
                }
            });

            table.render({
                elem: '#games'
                , id: 'games'
                , url: '/teacher/Game'
                , method: 'post'
                , width: 700
                , cols: [[
                    {type: 'numbers', title: '序号'},
                    {field: 'id', title: 'ID',width:80, sort: true,align:'center'},
                    {field: 'name', title: '游戏名', minwidth: 200, sort: true},
                    {field: 'price', edit: 'text', title: '分值', width: 80, align: 'center', sort: true},
                    {field: 'hits', title: '下载数', width: 90, align: 'center', sort: true},
                    {align: 'center', width: 120, toolbar: '#del', title: '操作'}
                ]]
                 , loading: false
                 , page: false
                 , even: true //表格隔行换色
            });


            var load;
            upload.render({
                elem: '#uploadGames'
                , url: 'addGames'
                , multiple: true
                , number:0
                , size: 0
                , accept: 'file' //普通文件
                , field:'file'
                , before: function () {//上传前触发
                    load = layer.load(); //上传loading
                }
                , allDone: function () { //当文件全部上传后，才触发
                    table.reload('games');
                    layer.close(load);
                    layer.msg('上传成功！', {icon: 6})
                }
            });

            //监听单元格编辑
            table.on('edit(games)', function (obj) {
                $.post('/teacher/edtGame', obj.data, function (r) {
                    (r == 'ok') ? layer.msg('修改成功') : null;
                });
            });


        });
</script>
<?php include 'inc/teacher_foot.php';?>
